package com.bw.module_home.ui.marketers

import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_common.base.BaseActivity
import com.bw.module_home.R
import com.bw.module_home.databinding.ActivityResidencyApplicationBinding
import com.bw.module_home.marketer.adapter.ResidencyApplicationAdapter
import com.bw.module_home.marketer.viewmodel.MarketersViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/module_marketers/residencyApplicationActivity")
class ResidencyApplicationActivity : BaseActivity<MarketersViewModel, ActivityResidencyApplicationBinding>() {

    lateinit var residencyApplicationAdapter: ResidencyApplicationAdapter
    private val viewModel: MarketersViewModel by viewModels()

    override val mLayoutResId: Int
        get() = R.layout.activity_residency_application

    override fun initView() {
        super.initView()
        mBinding.ivBack.setOnClickListener {
            finish()
        }
        residencyApplicationAdapter = ResidencyApplicationAdapter()
        mBinding.rvResidencyApplication.layoutManager = LinearLayoutManager(this)
        mBinding.rvResidencyApplication.adapter = residencyApplicationAdapter
        viewModel.getResidencyApplicationList()
        residencyApplicationAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/module_marketers/residencyApplicationDetailActivity")
                .withInt("detailId", residencyApplicationAdapter.data[position].id)
                .navigation()
        }
    }

    override fun initListener() {
        super.initListener()
        viewModel.getResidencyApplicationListSuccess.observe(this) {
            residencyApplicationAdapter.data.clear()
            residencyApplicationAdapter.data.addAll(it)
            residencyApplicationAdapter.notifyDataSetChanged()
        }
    }
}